<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
        #map{width:100%;height:100%;}
        p{margin-left:5px; font-size:14px;}
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=wBxM9CeVsHgYKxWUFHe61fTqQAbytN9s"></script>
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
    <title>地图分布</title>
</head>
<body>
<div id="map"></div>
<p>点击标注点，可查看由纯文本构成的简单型信息窗口</p>
</body>
</html>
<script type="text/javascript">
    function getQueryVariable(variable)
    {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    }
    var id=getQueryVariable("id")
        if(id==1){
                url="/portal/index/qianshou_map"
        }else{
            url="/portal/index/zhuomu_map"
        }
    //获取护学岗接口数据
    $.ajax({
        type: "post",
        url: url,
        dataType: "json",
        success: function(res){
            console.log(res)
            var opts = {
                width : 250,     // 信息窗口宽度
                height: 80,     // 信息窗口高度
                title : res.title, // 信息窗口标题
                enableMessage:true//设置允许信息窗发送短息
            };
            var map = new BMap.Map("map");
            map.centerAndZoom(new BMap.Point(res.center[0],res.center[1]), 12);
            get_map(res,opts,map)

        }
    });


    function get_map(res,opts,map){
        // 百度地图API功能s
        //data_info.point
        map.centerAndZoom(new BMap.Point(res.center[0],res.center[1]), 12);
        for(var i=0;i<res.point.length;i++){
            var marker = new BMap.Marker(new BMap.Point(res.point[i][0],res.point[i][1]));  // 创建标注
            var content = res.content[i];
            map.addOverlay(marker);               // 将标注添加到地图中
            addClickHandler(content,marker,opts,map);
        }
    }

    function addClickHandler(content,marker,opts,map){
        marker.addEventListener("click",function(e){
            openInfo(content,e,opts,map)}
        );
    }
    function openInfo(content,e,opts,map){
        var p = e.target;
        var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
        var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象
        map.openInfoWindow(infoWindow,point); //开启信息窗口
    }

</script>
